x = torch.ones(2, 3)*0.2
net1 = nn.Linear(3, 3)
net2 = nn.Linear(3, 3)
loss_fun = torch.nn.MSELoss()
tgt1 = torch.ones(2, 3)*0.5
pred1 = net1(x)
loss1=loss_fun(pred1, tgt1) # 计算图1
tgt2 = torch.ones(2, 3)
pred2 = net2(pred1)  # 此处修改,传入pred1
loss2 = loss_fun(pred2, tgt2) # 计算图2
# ------
tol_loss= loss2+loss1
# &&&&&&
# tol_loss.backward() # 梯度之和等于和的梯度
loss1.backward()  # 分别求梯度
loss2.backward()
# ++++++  
